<form action="<{link app=b2c ctl=site_member act=reAddCart }>" method="post">
    <!-- 购物车内容 -->
    <table id="cart_main" class="cart-main" width="100%">
        <colgroup>
            <col class="col-2">
            <col class="col-3">
            <col class="col-4">
            <col class="col-5">
            <col class="col-6">
            <col class="col-7">
            <col class="col-8">
            <col class="col-1">
        </colgroup>
        <thead>
        <tr>
            <th colspan="5"><{t}>商品<{/t}></th>
            <th colspan="3"><{t}>调整码单<{/t}></th>
        </tr>
        </thead>
        <{if $goods}>
        <{foreach from=$goods item=goods key=key}>
        <tbody class="cart-item">
        <!-- 主商品 -->
        <tr class="cart-product cart-product-<{$goods.product_id}>">
            <td colspan="3">
                <input type="hidden" name="goods[goods_id][]" value="<{$goods.goods_id}>">
                <input type="hidden" name="goods[product_id][]" value="<{$goods.product_id}>"/>
                <input type="hidden" name="goods[num][]" value="<{$goods.nums}>"/>
                <input type="hidden" name="goods[juanshu][]" value="<{$goods.juanshu}>"/>
                <input type="hidden" name="goods[madan_ids][]" value="<{$goods.madan_ids}>"/>
                <input type="hidden" name="goods[cntM][]" value="<{$goods.cntM}>"/>
                <input type="hidden" name="stock[]" value="<{$goods.store}>"/>
                <div class="p-pic">
                    <a href="<{link app=b2c ctl=site_product act=index arg0=$goods.product_id}>"
                       target="_blank"><img
                            src="<{$goods.obj_items.products.0.default_image.thumbnail|default:$env.conf.site.default_thumbnail_pic|storager:'s'}>"
                            alt="<{$goods.name}>"></a></div>
            </td>
            <td class="p-info" colspan="2">
                <div class="p-title">
                    <a target="_blank"
                       href="<{link app=b2c ctl=site_product arg0=$goods.product_id}>"><{$goods.name}></a>
                </div>
                <div class="p-spec ">
                    <{t}>类型：<{$goods.type}><{/t}>
                </div>
            </td>
            <td class="p-subtotal" colspan="3">
                <{if $goods.isYang}>
                    ---
                <{else}>
                <button type="button" onclick="picking(this,'<{$goods.product_id}>');" class="btn-peihuo">配货</button>
                <{/if}>
            </td>
        </tr>
        </tbody>
        <{/foreach}>
        <{/if}>
        <tfoot>
        <tr>

            <td colspan="4" class="cart-right">
                <{button type="submit" class="btn-import btn-huge action-settle" rel="_request"
                label=$___b2c="加入购物车"|t:'b2c'}>
            </td>
        </tr>
        </tfoot>
    </table>
</form>

<script>
    function picking(obj,product_id) {
        showDiv(product_id, function () {
            var tbody=$$(obj).getParent('.cart-item');
            var inputIds = $$(tbody).getElement('[name="goods[madan_ids][]"]');
            var inputMi = $$(tbody).getElement('[name="goods[num][]"]');
            var inputJu = $$(tbody).getElement('[name="goods[juanshu][]"]');
            var madan_ids = inputIds.get('value');
            var mishu = inputMi.get('value');
            var juanshu = inputJu.get('value');
            if (madan_ids != '') {
                var arr = madan_ids[0].split(',');//注split可以用字符或字符串分割
                for (var i = 0; arr[i]; i++) {
                    $$("[id='chkRoll[" + arr[i] + "]']").set('checked', 'checked');
                    // console.log();
                }
                //往选中之中填值
                //合计显示在页面上
                var totalStr = "<b><{t}>选中<{/t}>:" + "<font color='red'>" + juanshu + "</font>&nbsp;&nbsp;<{t}>卷<{/t}>&nbsp;&nbsp;<{t}>共<{/t}>:" + "<font color='red'>" + mishu + "</font>&nbsp;&nbsp;M</b> <div type='hidden' id='total' value='" + mishu + "' cntJuan='" + juanshu + "' madan_ids='" + madan_ids + "'></div> ";
                var spanDiv = window.document.getElementById("divTotal");
                spanDiv.innerHTML = totalStr;
            }
        });
    }
    function showDiv(product_id,onShow) {
        var dialog = new Dialog('<{link app=b2c ctl=site_order act=select_bujuan args0=1}>', {
            width: 600,
            height: 600,
            title: '<{t}>选择布卷<{/t}>',
            modal: true,
            async: 'ajax',
            asyncOptions: {
                method: 'post',
                data: 'product_id='+product_id,
                onComplete: function() {
                    onShow();
                }
            }
        });
        closeDiv = function() {
            dialog.hide();
        }
    }
</script>